<?php

namespace Admin\Controller;
use Think\Controller;

class GameuserController extends Controller{
	

	/*添加游戏平台用户*/

	public function add(){

		$head = I('post.head');
		$nickname = I('post.nickname');

		$gender = I('post.gender');
		$birthday = I('post.birthday');
		$phone = I('post.phone');

		$data['head'] = $head;
		$data['nickname'] = $nickname;
		$data['old'] = $old;
		$data['gender'] = $gender;
		$data['birthday'] = $birthday;
		$data['phone'] = $phone;

		$game = M('game');

		$result = $game->add($data);

		if($result!=false){

			$ajaxReturn['code'] = 1;
			$ajaxReturn['msg'] = '添加成功！';

		}else{

			$ajaxReturn['code'] = 2;
			$ajaxReturn['msg'] = "添加失败！";

		}

		$this->ajaxReturn($ajaxReturn);
	}

	/*删除游戏平台用户*/

	public function delete(){

		$id = I('post.id');

		$game = M('game');

		$result = $game->where('id='.$id)->delete();

		if($result!=false){

			$ajaxReturn['code'] = 1;
			$ajaxReturn['msg'] = '添加成功！';

		}else{

			$ajaxReturn['code'] = 2;
			$ajaxReturn['msg'] = "添加失败！";

		}

		$this->ajaxReturn($ajaxReturn);

	}

	/*修改用户信息列表*/

	public function infos(){

		$id = I('post.id');

		$game = M('game');

		$result = $game->where('id='.$id)->find();

		if($result!=false){

			$ajaxReturn['code'] = 1;
			$ajaxReturn['msg'] = '添加成功！';
			$ajaxReturn['data'] = $result;

		}else{

			$ajaxReturn['code'] = 2;
			$ajaxReturn['msg'] = "添加失败！";

		}

		$this->ajaxReturn($ajaxReturn);
	}

	/*修改用户信息*/

	public function save(){

		$id = I('post.id');
		$head = I('post.head');
		$nickname = I('post.nickname');

		$gender = I('post.gender');
		$birthday = I('post.birthday');
		$phone = I('post.phone');

		$data['head'] = $head;
		$data['nickname'] = $nickname;

		$data['gender'] = $gender;
		$data['birthday'] = $birthday;
		$data['phone'] = $phone;

		$game = M('game');

		$result = $game->where('id='.$id)->save($data);

		if($result!=false){

			$ajaxReturn['code'] = 1;
			$ajaxReturn['msg'] = '添加成功！';

		}else{

			$ajaxReturn['code'] = 2;
			$ajaxReturn['msg'] = "添加失败！";

		}

		$this->ajaxReturn($ajaxReturn);

	}

	/*用户列表*/
	public function lists(){

		$this->isAjaxLogin();//检查是否登录

        $page = I('post.page');//当前页数
        $page_size = I('post.page_size');

        $game=M('game');

        $count = $game->count();
        $total =  ceil($count / $page_size);
        $limitStart = ($page-1) * $page_size;
        
        $result=$game->order("id desc")->limit($limitStart,$page_size)->select();

        if($result !== false){

            $data['page']['total_page'] = $total;
            $data['list'] = $result;
            

            $ajaxReturn['code'] = 1;
            $ajaxReturn['msg'] = "SUCCESS";
            $ajaxReturn['data'] = $data;
        }else{

            $ajaxReturn['code'] = 2;
            $ajaxReturn['msg'] = "数据查询失败！";
        }
        $this->ajaxReturn($ajaxReturn);

	}

}